<template>
  <!-- <div class="home"> -->
  <!-- <div class="title">
            <p>新增人员</p>
          </div> -->
  <div class="home">
    <!-- 一级信息 -->
    <div class="main-title row">
      <div style="width: 20%">一级信息</div>
      <div style="width: 80%; text-align: right; margin-right: 20px">
        <el-button class="sub-btn" @click="onSubmit">提交</el-button>
      </div>
    </div>
    <div class="main-body">
      <el-form
        class="body-form"
        :model="infoLevel1"
        label-width="130px"
        :inline="true"
        :rules="rulesInfoLevel1"
      >
        <el-form-item
          class="form-item"
          prop="servicesCompany"
          label="所属劳务公司:"
        >
          <el-select
            class="add-menu-level"
            v-model="infoLevel1.servicesCompany"
            placeholder="请选择劳务公司"
            @change="getTeamList"
            :disabled="disableCorpAndTeam"
          >
            <el-option
              v-for="item in servicesCompanyList"
              :key="item.serviceCorporationId"
              :label="item.name"
              :value="item.serviceCorporationId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form-item" prop="team" label="所属班组:">
          <el-select
            class="add-menu-level"
            v-model="infoLevel1.team"
            placeholder="请选择班组"
            :disabled="disableCorpAndTeam"
          >
            <el-option
              v-for="item in teamList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form-item" prop="type" label="请选择工种:">
          <el-select
            class="add-menu-level"
            v-model="infoLevel1.type"
            placeholder="请选择工种"
          >
            <el-option
              v-for="item in typeList"
              :key="item.id"
              :label="item.workTypeName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form-item" prop="name" label="姓名:">
          <el-input v-model="infoLevel1.name" :disabled="isDisabled"></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="birth" label="出生日期:">
          <!-- <el-input  v-model="infoLevel1.birth"></el-input> -->
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="infoLevel1.birth"
            style="width: 220px"
            :disabled="isDisabled"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="form-item" prop="sex" label="性别:">
          <el-select
            class="add-menu-level"
            v-model="infoLevel1.sex"
            placeholder="请选择性别"
            :disabled="isDisabled"
          >
            <el-option
              v-for="item in sexList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-item"
          prop="certificateType"
          label="证件类型:"
        >
          <el-select
            class="add-menu-level"
            v-model="infoLevel1.certificateType"
            placeholder="身份证"
            :disabled="isDisabled"
            @change="certificateTypeChange"
          >
            <el-option
              v-for="item in certificateTypeList"
              :key="item.label"
              :label="item.label"
              :value="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form-item" prop="licenseNumber" label="证件号:">
          <el-input
            v-model="infoLevel1.licenseNumber"
            :disabled="isDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="validPeriod" label="证件有效期:">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="infoLevel1.validPeriod"
            style="width: 220px"
            :disabled="isDisabled"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="form-item" prop="ethnicGroup" label="民族:">
          <el-input
            v-model="infoLevel1.ethnicGroup"
            :disabled="isDisabled"
          ></el-input>
        </el-form-item>
        <el-form-item
          class="form-item address"
          prop="address"
          label="家庭住址:"
        >
          <el-input v-model="infoLevel1.address" clearable></el-input>
          <!-- <el-tooltip
            effect="dark"
            :content="infoLevel1.address"
            placement="top"
            :disabled="infoLevel1.address==''"
          >
            <el-input v-model="infoLevel1.address"></el-input>
          </el-tooltip> -->
        </el-form-item>
      </el-form>
    </div>
    <!-- 二级信息 -->
    <div class="main-title row">
      <div style="width: 20%">二级信息</div>
      <div style="width: 80%; text-align: right; margin-right: 20px">
        <el-button style="padding-left: 13px" class="sub-btn" @click="toGPY"
          >拍照上传</el-button
        >
      </div>
    </div>
    <div class="main-body">
      <el-form
        class="body-form"
        :model="infoLevel2"
        label-width="130px"
        :inline="true"
        :rules="rulesInfoLevel2"
      >
        <el-form-item class="form-item" prop="phone" label="联系方式:">
          <el-input v-model="infoLevel2.phone"></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="hometown" label="籍贯:">
          <el-input v-model="infoLevel2.hometown"></el-input>
        </el-form-item>
        <el-form-item
          class="form-item"
          prop="politicalStatus"
          label="政治面貌:"
        >
          <el-select
            class="add-menu-level"
            v-model="infoLevel2.politicalStatus"
            placeholder="政治面貌"
          >
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="form-item" prop="nationality" label="国籍:">
          <el-input v-model="infoLevel2.nationality"></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="postcode" label="邮编:">
          <el-input v-model="infoLevel2.postcode"></el-input>
        </el-form-item>
        <el-form-item
          class="form-item address"
          prop="address"
          label="现居住地:"
        >
          <el-input v-model="infoLevel2.address" clearable></el-input>
          <!-- <el-tooltip
            effect="dark"
            :content="infoLevel2.address"
            placement="top"
            :disabled="infoLevel2.address==''"
          >
            <el-input v-model="infoLevel2.address"></el-input>
          </el-tooltip> -->
        </el-form-item>
        <el-form-item
          class="form-item"
          prop="emergencyContact"
          label="紧急联系人:"
        >
          <el-input v-model="infoLevel2.emergencyContact"></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="ECphone" label="紧急联系人电话:">
          <el-input v-model="infoLevel2.ECphone"></el-input>
        </el-form-item>
        <el-form-item class="form-item" prop="IDPhoto" label="证件照:">
          <el-upload
            class="form-img"
            :action="BASE_API+'/sys/file/uploadImg'"
            :on-success="headSuccess"
            :show-file-list="false"
            :before-upload="beforeUpload"
          >
            <img
              v-if="infoLevel2.IDPhoto"
              :src="infoLevel2.IDPhoto"
              style="height: 180px; width: 180px"
            />
            <img
              v-else
              class="icon-add"
              style="width: 80px; height: 80px"
              src="./static/addImg.png"
            />
          </el-upload>
        </el-form-item>
        <el-form-item class="form-item" prop="facade" label="身份证:">
          <div class="row">
            <el-upload
              class="form-img"
              style="margin-left: -1px"
              :on-success="faceSuccess"
              :action="BASE_API+'/sys/file/uploadImg'"
              :show-file-list="false"
              :before-upload="beforeUpload"
            >
              <img
                v-if="infoLevel2.facade"
                :src="infoLevel2.facade"
                style="width: 180px; height: 180px"
              />
              <div v-else>
                <img
                  class="icon-add"
                  style="width: 80px; height: 80px"
                  src="./static/addImg.png"
                />
                <p style="margin-top: -25px">(正面)</p>
              </div>
            </el-upload>
            <el-upload
              class="form-img"
              :action="BASE_API+'/sys/file/uploadImg'"
              :on-success="backSuccess"
              :show-file-list="false"
              :before-upload="beforeUpload"
            >
              <img
                v-if="infoLevel2.obverse"
                :src="infoLevel2.obverse"
                style="width: 180px; height: 180px"
              />
              <div v-else>
                <img
                  class="icon-add"
                  style="width: 80px; height: 80px"
                  src="./static/addImg.png"
                />
                <p style="margin-top: -25px">(反面)</p>
              </div>
            </el-upload>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <!-- 银行卡信息 -->
    <div class="main-title row">
      <div style="width: 20%">银行卡信息</div>
    </div>
    <div class="main-body">
      <el-form
        class="body-form form-center"
        :model="bankCardInfo"
        label-width="130px"
        :inline="true"
      >
        <el-form-item class="form-item" label="收款方:">
          <el-input v-model="bankCardInfo.beneficiary"></el-input>
        </el-form-item>
        <el-form-item class="form-item" label="开户人姓名:">
          <el-input v-model="bankCardInfo.name"></el-input>
        </el-form-item>
        <el-form-item
          prop="number"
          :rules="[{ type: 'number', message: '银行卡号必须为数字值' }]"
          class="form-item"
          label="银行卡号:"
        >
          <el-input v-model.number="bankCardInfo.number"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <!-- 工资设置 -->
    <div class="main-title row">
      <div style="width: 20%">工资设置</div>
    </div>
    <div class="main-body">
      <el-form
        class="body-form form-center"
        :model="WageSetting"
        label-width="130px"
        :inline="true"
        :rules="rulesWageSetting"
      >
        <el-form-item class="form-item" label="日工资金额:" prop="SalaryAmount">
          <el-input v-model.number="WageSetting.SalaryAmount"></el-input>
        </el-form-item>
        <el-form-item
          class="form-item"
          label="日生活费金额:"
          prop="LivingExpenses"
        >
          <el-input v-model.number="WageSetting.LivingExpenses"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
  <!-- </div> -->
</template>

<script>
import axios from "axios";
import {
  getWorkType,
  getServiceCorporation,
  getTree,
  insertPersonnel,
  getPersonnelById,
  updatePersonnel,
} from "@/api/worker.js";
export default {
  data() {
    var validateCert = (rule, value, callback) => {
      if (!this.regular.test(value)) {
        callback(new Error("请输入正确的证件号"));
      } else {
        callback();
      }
    };
    return {
      projectId: localStorage.getItem("projectId"),
      img: {
        head: "",
        face: "",
        back: "",
      },
      regular:
        /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
      message: "",
      isDisabled: false,
      disableCorpAndTeam: false,
      personId: null,
      fileURL: null,
      BASE_API: process.env.BASE_API,
      sexList: [
        {
          value: 1,
          label: "男",
        },{
          value: 0,
          label: "女",
        }
      ],
      certificateTypeList: [
        {
          value: 1,
          label: "居民身份证",
        },
        {
          value: 2,
          label: "护照",
        },
        {
          value: 3,
          label: "港澳通行证",
        },
        {
          value: 4,
          label: "台湾通行证",
        },
      ],
      typeList: [
        {
          value: 1,
          label: "工种1",
        },
        {
          value: 2,
          label: "工种2",
        },
        {
          value: 3,
          label: "工种3",
        },
      ],
      servicesCompanyList: [
        {
          value: 1,
          label: "劳务公司1",
        },
        {
          value: 2,
          label: "劳务公司2",
        },
        {
          value: 3,
          label: "劳务公司3",
        },
      ],
      teamList: null,
      infoLevel1: {
        servicesCompany: "", //所属劳务公司
        team: "", // 所属班组
        type: "", // 工种
        name: "", // 姓名
        birth: "", // 出生日期
        sex: "", // 性别
        certificateType: "居民身份证", // 证件类型
        licenseNumber: "", // 证件号
        validPeriod: "", // 证件有效期
        ethnicGroup: "", // 民族
        address: "", // 家庭住址
      },
      rulesInfoLevel1: {
        servicesCompany: [
          {
            required: true,
            message: "请选择所属劳务公司",
            trigger: "change",
          },
        ],
        team: [
          {
            required: true,
            message: "请选择所属班组",
            trigger: "change",
          },
        ],
        type: [
          {
            required: true,
            message: "请选择工种",
            trigger: "change",
          },
        ],
        name: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
          {
            min: 2,
            max: 10,
            message: "长度在 2 到 10 个字符",
            trigger: "blur",
          },
        ],
        // birth: [
        //   {
        //     type: "date",
        //     required: true,
        //     message: "请选择出生日期",
        //     trigger: "change",
        //   },
        // ],
        sex: [
          {
            required: true,
            message: "请选择性别",
            trigger: "change",
          },
        ],
        ethnicGroup: [
          {
            required: true,
            message: "请输入民族",
            trigger: "blur",
          },
        ],
        certificateType: [
          {
            required: true,
            message: "请选择证件类型",
            trigger: "change",
          },
        ],
        licenseNumber: [
          {
            required: true,
            message: "请输入证件号",
            trigger: "blur",
          },
          {
            validator: validateCert,
            trigger: "blur",
          },
        ],
        // validPeriod: [
        //   {
        //     required: true,
        //     type: "date",
        //     message: "请选择证件有效期",
        //     trigger: "change",
        //   },
        // ],
        // address: [
        //   {
        //     required: true,
        //     message: "请输入家庭住址",
        //     trigger: "blur",
        //   },
        // ],
      },
      infoLevel2: {
        phone: "", //联系方式
        hometown: "", // 籍贯
        politicalStatus: "", // 政治面貌
        nationality: "中国", // 国籍
        postcode: "", // 邮编
        address: "", // 现居地
        emergencyContact: "", // 紧急联系人
        ECphone: "", // 紧急联系人电话
        IDPhoto: "", // 证件照
        facade: "", // 身份证正
        obverse: "", // 身份证反
      },
      rulesInfoLevel2: {
        phone: [
          {
            required: true,
            message: "请输入联系方式",
            trigger: "blur",
          },
          { min: 11, max: 11, message: "请输入11位手机号码", trigger: "blur" },
          {
            pattern:
              /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/,
            message: "请输入正确的手机号码",
          },
        ],
        nationality: [
          {
            required: true,
            message: "请输入国籍",
            trigger: "blur",
          },
        ],
        // hometown: [
        //   {
        //     required: true,
        //     message: "请输入籍贯",
        //     trigger: "blur",
        //   },
        // ],
        // politicalStatus: [
        //   {
        //     required: true,
        //     message: "请选择政治面貌",
        //     trigger: "change",
        //   },
        // ],

        //   postcode: [
        //     {
        //       required: true,
        //       message: "请输入邮编",
        //       trigger: "blur",
        //     },
        //     { min: 6, max: 6, message: "请输入6位邮政编码", trigger: "blur" },
        //     {
        //       pattern:
        //         /^[0-9]{6}$/,
        //       message: "请输入正确的邮政编码",
        //     },
        //   ],
        //   address: [
        //     {
        //       required: true,
        //       message: "请输入现居地",
        //       trigger: "blur",
        //     },
        //   ],
        //   emergencyContact: [
        //     {
        //       required: true,
        //       message: "请输入紧急联系人",
        //       trigger: "blur",
        //     },
        //   ],
        //   ECphone: [
        //     {
        //       required: true,
        //       message: "请输入紧急联系人电话",
        //       trigger: "blur",
        //     },
        //     { min: 11, max: 11, message: "请输入11位手机号码", trigger: "blur" },
        //     {
        //       pattern:
        //         /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/,
        //       message: "请输入正确的手机号码",
        //     },
        //   ],
        //   IDPhoto: [
        //     {
        //       required: true,
        //       message: "请上传证件照",
        //       trigger: "blur",
        //     },
        //   ],
        //   facade: [
        //     {
        //       required: true,
        //       message: "请上传身份证正面",
        //       trigger: "blur",
        //     },
        //   ],
      },
      statusList: [
        {
          value: 13,
          label: "群众",
        },
        {
          value: 3,
          label: "共青团员",
        },
        {
          value: 2,
          label: "中共预备党员",
        },
        {
          value: 1,
          label: "中共党员",
        },
        {
          value: 14,
          label: "其他党派人士",
        },
        {
          value: 12,
          label: "无党派人士",
        },
      ],
      bankCardInfo: {
        beneficiary: "", //收款方
        name: "", // 开户姓名
        number: "", // 银行卡号
      },
      BasicType: [
        {
          value: 1,
          label: "按天结算",
        },
        {
          value: 2,
          label: "按小时结算",
        },
      ],
      LivingType: [
        {
          value: 1,
          label: "生活费工资类型1",
        },
        {
          value: 2,
          label: "生活费工资类型2",
        },
        {
          value: 3,
          label: "生活费工资类型3",
        },
      ],
      WageSetting: {
        Basic: "", //基本工资
        SalaryAmount: "", // 工资金额
        Living: "", // 生活费工资
        LivingExpenses: "", // 生活费金额
      },
      rulesWageSetting: {
        Basic: [
          {
            required: true,
            message: "请选择基本工资类型",
            trigger: "change",
          },
        ],
        SalaryAmount: [
          {
            required: true,
            message: "请输入工资金额",
            trigger: "blur",
          },
          {
            type: "number",
            message: "工资金额只能是数字",
            trigger: "blur",
          },
        ],
        Living: [
          {
            required: true,
            message: "请选择生活费工资类型",
            trigger: "change",
          },
        ],
        LivingExpenses: [
          {
            required: true,
            message: "请输入生活费金额",
            trigger: "blur",
          },
          {
            type: "number",
            message: "生活费只能是数字",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    getServiceCorporation(null).then((res) => {
      // console.log(res)
      this.servicesCompanyList = res.data.data.records;
    });
    getWorkType({status:1}).then((res) => {
      // console.log(res)
      this.typeList = res.data.data.records;
    });
    this.personId = this.$route.query.id;
    // console.log(this.$route);
    if (this.$route.query.corpId) {
      this.infoLevel1.servicesCompany = this.$route.query.corpId;
      this.getTeamList(this.infoLevel1.servicesCompany);
      this.infoLevel1.team = this.$route.query.teamId;
      this.disableCorpAndTeam = true;
    } else if (this.personId != null) this.getOldUpdata(this.personId);
    // this.infoLevel1.team = data.teamId
  },

  methods: {
    certificateTypeChange() {
      if (this.infoLevel1.certificateType == "居民身份证") {
        this.regular =
          /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
      } else if (this.infoLevel1.certificateType == "护照") {
        this.regular = /^([a-zA-z]|[0-9]){5,17}$/;
      } else if (this.infoLevel1.certificateType == "港澳通行证") {
        this.regular = /^([A-Z]\d{6,10}(\(\w{1}\))?)$/;
      } else if (this.infoLevel1.certificateType == "台湾通行证") {
        this.regular = /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/;
      }
    },
    checkInfoLevel1() {
      if (!this.infoLevel1.servicesCompany) {
        // console.log("请选择所属劳务公司");
        this.message = "请选择所属劳务公司";
        // this.$message.error(this.message);
        return false;
      } else if (!this.infoLevel1.team) {
        // console.log("所属班组");
        this.message = "请选择所属班组";
        return false;
      } else if (!this.infoLevel1.type) {
        // console.log("工种");
        this.message = "请选择工种";
        return false;
      } else if (!this.infoLevel1.name) {
        // console.log("姓名")
        this.message = "请输入姓名";
        return false;
      } else if (!(this.infoLevel1.sex + "")) {
        // console.log("性别")
        this.message = "请选择性别";
        return false;
      //else if (!this.infoLevel1.birth) {
      //   // console.log("出生日期")
      //   this.message = "请选择出生日期";
      //   return false;
      // } else if (!this.infoLevel1.certificateType) {
      //   // console.log("证件类型")
      //   this.message = "请选择证件类型";
      //   return false;
        } else if (!this.infoLevel1.licenseNumber) {
          // console.log("证件号")
          this.message = "请输入证件号";
          return false;
      }
      // else if (this.infoLevel1.licenseNumber) {
      else if (this.certificateType == 2) {
        this.regular = /^([a-zA-z]|[0-9]){5,17}$/;
      } else if (this.certificateType == 3) {
        this.regular = /^([A-Z]\d{6,10}(\(\w{1}\))?)$/;
      } else if (this.certificateType == 4) {
        this.regular = /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/;
      }
      // }
      else if (
        this.infoLevel1.licenseNumber &&
        !this.regular.test(this.infoLevel1.licenseNumber)
      ) {
        this.message = "请输入正确的证件号";
        return false;
        // } else if (!this.infoLevel1.validPeriod) {
        //   // console.log("证件有效期")
        //   this.message = "请选择证件有效期";
        //   return false;
      } else if (!(this.infoLevel1.ethnicGroup + "")) {
        // console.log("民族")
        this.message = "请输入民族";
        return false;
        // } else if (!this.infoLevel1.address) {
        //   // console.log("家庭住址")
        //   this.message = "请输入家庭住址";
        //   return false;
      } else {
        this.message = "";
        // console.log("都不为空")
        return true;
      }
    },
    checkInfoLevel2() {
      if (!this.infoLevel2.phone) {
        // console.log("联系方式")
        this.message = "请输入联系方式";
        return false;
      } else if (!/^1[34578]\d{9}$/.test(this.infoLevel2.phone)) {
        // console.log("请填写正确的手机号")
        this.message = "请填写正确的联系方式";
        return false;
        // } else if (!this.infoLevel2.hometown) {
        //   // console.log("籍贯")
        //   this.message = "请输入籍贯";
        //   return false;
        // } else if (!(this.infoLevel2.politicalStatus + "")) {
        //   // console.log(this.infoLevel2.politicalStatus)
        //   this.message = "请选择政治面貌";
        //   return false;
        // } else if (!this.infoLevel2.nationality) {
        //   // console.log("国籍")
        //   this.message = "请输入国籍";
        //   return false;
        // } else if (!this.infoLevel2.postcode) {
        //   // console.log("邮编")
        //   this.message = "请输入邮编";
        //   return false;
        // } else if (!this.infoLevel2.address) {
        //   // console.log("现居地")
        //   this.message = "请输入现居地";
        //   return false;
        // } else if (!this.infoLevel2.emergencyContact) {
        //   // console.log("紧急联系人")
        //   this.message = "请输入紧急联系人";
        //   return false;
        // } else if (!this.infoLevel2.ECphone) {
        //   // console.log("紧急联系人电话")
        //   this.message = "请输入紧急联系人电话";
        //   return false;
        // } else if (!/^1[34578]\d{9}$/.test(this.infoLevel2.ECphone)) {
        //   // console.log("请填写正确的紧急联系人电话")
        //   this.message = "请填写正确的紧急联系人电话";
        //   return false;
        // } else if (!this.infoLevel2.IDPhoto) {
        //   // console.log("证件照")
        //   this.message = "请上传证件照";
        //   return false;
        // } else if (!this.infoLevel2.facade) {
        //   // console.log("身份证正")
        //   this.message = "请上传身份证正面";
        //   return false;
        // } else if (!this.infoLevel2.obverse) {
        //   // console.log("身份证反")
        //   this.message = "请上传身份证反面";
        //   return false;
      } else {
        this.message = "";
        // console.log("都不为空")
        return true;
      }
    },
    checkWageSetting() {
      // if (!this.WageSetting.Basic) {
      //   console.log("基本工资");
      //   this.message = "请选择基本工资类型";
      //   return false;
      // } else
      if (!this.WageSetting.SalaryAmount) {
        console.log("工资金额");
        this.message = "请输入工资金额";
        return false;
      }
      //  else if (!this.WageSetting.Living) {
      //   console.log("生活费工资");
      //   this.message = "请选择生活费工资类型";
      //   return false;
      // }
      else if (!this.WageSetting.LivingExpenses) {
        console.log("生活费金额");
        this.message = "请输入生活费金额";
        return false;
      } else {
        // console.log("都不为空")
        this.message = "";
        return true;
      }
    },
    //获取修改信息
    getOldUpdata(id) {
      // console.log(id)
      this.isDisabled = true;
      getPersonnelById(id).then((res) => {
        // console.log(res)
        const data = res.data.data;
        this.infoLevel1 = {
          servicesCompany: data.serviceCorporationId,
          team: data.teamId, // 所属班组
          type: data.workTypeId, // 工种
          name: data.name, // 姓名
          birth: data.birthDate, // 出生日期
          sex: data.gender, // 性别
          certificateType: data.certificateType, // 证件类型
          licenseNumber: data.certificateNumber, // 证件号
          validPeriod: data.certificateValidPeriod, // 证件有效期
          ethnicGroup: data.clan, // 民族
          address: data.address, // 家庭住址
        };
        this.infoLevel2 = {
          phone: data.phone, //联系方式
          hometown: data.hometown, // 籍贯
          politicalStatus: data.politicalOutlookId, // 政治面貌
          nationality: data.country, // 国籍
          postcode: data.postcode, // 邮编
          address: data.currentResidence, // 现居地
          emergencyContact: data.emergencyContact, // 紧急联系人
          ECphone: data.emergencyContactPhone, // 紧急联系人电话
          IDPhoto: data.idPhoto, // 证件照
          facade: data.idPhotoPositive, // 身份证正
          obverse: data.idPhotoObverse, // 身份证反
        };
        this.bankCardInfo = {
          beneficiary: data.payee, //收款方
          name: data.bankName, // 开户姓名
          number: data.bankCardNumber, // 银行卡号
        };
        this.WageSetting = {
          // Basic: data., //基本工资
          SalaryAmount: data.dailyWage, // 工资金额
          // Living: data., // 生活费工资
          LivingExpenses: data.alimony, // 生活费金额
        };
        // console.log("this.infoLevel1.servicesCompany:"+this.infoLevel1.servicesCompany)
        if (this.infoLevel1.servicesCompany) {
          this.getTeamList(this.infoLevel1.servicesCompany);
        }
      });
    },
    // 获取班组列表
    getTeamList(serviceCorporationId) {
      // console.log("获取班组列表,劳务公司id:"+serviceCorporationId)
      if (serviceCorporationId != null) {
        // console.log(serviceCorporationId)
        getTree().then((res) => {
          // console.log(res)
          const team = res.data.data.filter((e) => {
            return e.id == serviceCorporationId;
          });
          if (team.length > 0) {
            this.teamList = team[0].children;
          } else this.teamList = null;
        });
      }
    },
    onSubmit() {
      var moment = require("moment");
      // const data = {
      //   address: "111111",
      //   alimony: "222",
      //   bankCardNumber: "11111111",
      //   bankName: "w",
      //   birthDate: "2021-07-11",
      //   certificateNumber: "111111",
      //   certificateType: 1,
      //   certificateValidPeriod: "2021-07-11",
      //   clan: "1",
      //   country: "1",
      //   currentResidence: "111",
      //   dailyWage: "222",
      //   email: "",
      //   emergencyContact: "q",
      //   emergencyContactPhone: undefined,
      //   gender: 1,
      //   hometown: "h",
      //   idPhotoObverse:
      //     "blob:http://localhost:81/b8e7fcbc-9fba-452d-a0d2-235b5389cdc1",
      //   idPhotoPositive:
      //     "blob:http://localhost:81/78891c33-749b-48b2-829f-ccd3b526e948",
      //   name: "111",
      //   openAccount: 0,
      //   payee: "q",
      //   phone: "12112312123",
      //   politicalOutlookId: 0,
      //   postcode: "111",
      //   projectId: 2,
      //   serviceCoporationId: 1,
      //   teamId: 1,
      //   workTypeId: 2,
      // };
      // console.log(this.infoLevel2);
      // if(this.personId){
      //   console.log("update")
      // }else console.log("add")
      if (
        this.checkInfoLevel1() &&
        this.checkInfoLevel2() &&
        this.checkWageSetting()
      ) {
        console.log("submit!");
        const data = {
          address: this.infoLevel1.address,
          alimony: this.WageSetting.LivingExpenses,
          bankCardNumber: this.bankCardInfo.number,
          bankName: this.bankCardInfo.name,
          birthDate:
            this.infoLevel1.birth == ""
              ? ""
              : moment(this.infoLevel1.birth).format("YYYY-MM-DD"),
          certificateNumber: this.infoLevel1.licenseNumber,
          certificateType: this.infoLevel1.certificateType,
          // certificateType: "居民身份证",
          certificateValidPeriod:
            this.infoLevel1.validPeriod == ""
              ? ""
              : moment(this.infoLevel1.validPeriod).format("YYYY-MM-DD"),
          clan: this.infoLevel1.ethnicGroup,
          // clan:0,
          country: this.infoLevel2.nationality,
          currentResidence: this.infoLevel2.address,
          dailyWage: this.WageSetting.SalaryAmount,
          email: "",
          emergencyContact: this.infoLevel2.emergencyContact,
          emergencyContactPhone: this.infoLevel2.ECphone,
          gender: this.infoLevel1.sex,
          hometown: this.infoLevel2.hometown,
          idPhoto: this.infoLevel2.IDPhoto,
          idPhotoObverse: this.infoLevel2.obverse,
          idPhotoPositive: this.infoLevel2.facade,
          name: this.infoLevel1.name,
          openAccount: 0, //没写
          payee: this.bankCardInfo.beneficiary,
          phone: this.infoLevel2.phone,
          politicalOutlookId: this.infoLevel2.politicalStatus,
          postcode: this.infoLevel2.postcode,
          projectId: this.projectId,
          serviceCorporationId: this.infoLevel1.servicesCompany,
          teamId: this.infoLevel1.team,
          workTypeId: this.infoLevel1.type,
        };
        if (this.personId) {
          data.personId = this.personId;
          // console.log("xiugai")
          updatePersonnel(data)
            .then((res) => {
              this.$message({
                type: "success",
                message: "修改成功！",
              });
              this.$router.push({ path: "/worker/list" });
            })
            .catch((res) => {
              this.$message({
                type: "error",
                message: res.message,
              });
            });
        } else {
          //  console.log("tianjai")
          insertPersonnel(data).then((res) => {
            // console.log(res);
            this.$message({
              type: "success",
              message: "添加成功！",
            });
            this.$router.push({ path: "/worker/list" });
          });
          // .catch(res=>{
          //   console.log("添加失败",res);
          //   this.$message({
          //     type: "error",
          //     message: res.message,
          //   });
          // });
        }
      } else {
        if (this.message) this.$message.error(this.message);
        // console.log(this.infoLevel1);
        // console.log("信息填写出错")
      }
    },
    headSuccess(res, file) {
      this.infoLevel2.IDPhoto = res.data.imgurl;
      // this.img.head = URL.createObjectURL(file.raw);
    },
    faceSuccess(res, file) {
      this.infoLevel2.facade = res.data.imgurl;
      // this.img.face = URL.createObjectURL(file.raw);
    },
    backSuccess(res, file) {
      this.infoLevel2.obverse = res.data.imgurl;
      // this.img.back = URL.createObjectURL(file.raw);
    },
    beforeUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt1M = file.size / 1024 / 1024 < 1;
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt1M) {
        this.$message.error("上传头像图片大小不能超过 1MB!");
      }
      return isJPG && isLt1M;
    },
    toGPY() {
      this.$router.push({
        path: "/quickFiling/workerImport",
        query: { personId: this.personId },
      });
    },
    // beforeHeadUpload(file) {
    //   if(this.typeCheck(file)){
    //     const name = this.infoLevel1.licenseNumber
    //     const copyFile = new File([file],`${name}H.jpg`)
    //     const formdata = new FormData()
    //     formdata.append('file', copyFile)
    //     axios.post('http://gz.haogzl.com:8222/sys/file/uploadImg',formdata).then(res=>{
    //       console.log(res);
    //       this.infoLevel2.IDPhoto = res.data.data.imgurl;
    //       console.log(formdata.get('file'));
    //       this.img.head = URL.createObjectURL(formdata.get('file'))
    //     }).catch(res=>{
    //       console.log(1,res);
    //     })
    //   }
    //     return false
    // },
    // beforeFaceUpload(file) {
    //   if(this.typeCheck(file)){
    //     const name = this.infoLevel1.licenseNumber
    //     if(!name){
    //       this.$message.error("请先输入证件号码");
    //     }
    //     const copyFile = new File([file],`${name}F.jpg`)
    //     const formdata = new FormData()
    //     formdata.append('file', copyFile)
    //     axios.post('http://gz.haogzl.com:8222/sys/operlog/uploadImg',formdata).then(res=>{
    //       console.log(res);
    //       this.infoLevel2.facade = res.data.data.imgurl;
    //       this.img.face = URL.createObjectURL(formdata.get('file'))
    //     }).catch(res=>{
    //       console.log(1,res);
    //     })
    //   }
    //     return false
    // },
    // beforeBackUpload(file) {
    //   if(this.typeCheck(file)){
    //     const name = this.infoLevel1.licenseNumber
    //     if(!name){
    //       this.$message.error("请先输入证件号码");
    //     }
    //     const copyFile = new File([file],`${name}B.jpg`)
    //     const formdata = new FormData()
    //     formdata.append('file', copyFile)
    //     axios.post('http://gz.haogzl.com:8222/sys/operlog/uploadImg',formdata).then(res=>{
    //       console.log(res);
    //       this.infoLevel2.obverse = res.data.data.imgurl;
    //       console.log(formdata.get('file'));
    //       this.img.back = URL.createObjectURL(formdata.get('file'))
    //     }).catch(res=>{
    //       console.log(1,res);
    //     })
    //   }
    //     return false
    // },
  },
};
</script>

<style lang="scss" scoped>
html,
body,
#app {
  height: 100%;
}

.home {
  min-height: 100%;
  width: 100%;
  min-width: 750px;
  background-color: #f8f8f9;
}

.title {
  text-align: left;
  /* width: 100%; */
  padding-left: 20px;
  border: solid 1px #e4e4e4;
  height: 55px;
  line-height: 20px;
  background-color: #f3f3f3;
  color: #999999;
  padding-top: 20px;
  padding-left: 20%;
  font-size: 13px;
}

.title p {
  height: 20px;
  margin: 0;
  padding-left: 5px;
  border-left: solid 3px #1abc9c;
}

.row {
  display: flex;
  flex-direction: row;
}

.main {
  margin-top: 20px;
  // width: 1100px;
  width: 100%;
  // border: solid 1px #e4e4e4;
  padding-top: 0;
  padding-bottom: 20px;
  /* width: 80%; */
  margin-left: 20%;
  height: 100%;
  text-align: center;
}

.main-title {
  height: 40px;
  text-align: left;
  padding-left: 20px;
  font-size: 14px;
  color: #333333;
  line-height: 40px;
  .sub-btn {
    margin-left: 22%;
    background-color: #1abc9c;
    color: #ffffff;
    width: 80px;
    height: 35px;
    padding-top: 0;
    line-height: 35px;
  }
}

.main-body {
  // border: solid 1px #e4e4e4;
  min-height: 150px;
  background-color: #ffffff;
  padding-top: 10px;
  padding-left: 10px;
}

.form-item {
  min-height: 50px;
  line-height: 50px;
}

.body-form {
  text-align: left;
}

.form-center {
  padding-left: 150px;
  // padding: 0 auto;
  // text-align: center;
}

.body-form .el-select {
  width: 220px;
  /* width: 50%; */
  margin-top: 10px;
}

.form-item .el-input {
  width: 220px;
  margin-top: 10px;
  border-radius: 0;
}
// .address{
//     display: block;
//     width: 100%;
// }
.address .el-input {
  width: 585px;
  // width: 220px;
  // max-width: 585px;
}

.form-item .el-input__inner {
  border-radius: 0;
}

.form-img {
  width: 180px;
  height: 180px;
  margin-right: 42px;
  text-align: center;
  border: solid 1px #e4e4e4;
}

.form-img .icon-add {
  margin-top: 50px;
}
/* .form-item.el-form-item__content.el-input .el-input__inner {
        height: 40px;
        border-radius: 0;
    } */
</style>
